//
//  MyInforChangePhoneViewController.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/4.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "MyInforChangePhoneViewController.h"
#import "LGetCodeView.h"
#import "MyInforChangeDetailViewController.h"
@interface MyInforChangePhoneViewController ()<GetCodeDelegate>
/**  获取验证码  */
@property (strong, nonatomic) LGetCodeView  *getCode;
/**  修改手机号  */
@property (strong, nonatomic) UIButton  *changePhoneButton;

@end

@implementation MyInforChangePhoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = @"修改手机号";
    [self.view addSubview:self.getCode];
    [self.view addSubview:self.changePhoneButton];
}

/**  获取验证码  */
- (void)LGetCodeWith:(LGetCodeView *)view click:(BOOL)click{
    
    [self.getCode.codeButton startWithTime:59 title:@"获取验证码" countDownTitle:@"重新获取" mainColor:[UIColor whiteColor] countColor:[UIColor blackColor]];

    
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    paramer[@"MOBILE"] = [ZJUserInfoModel sharedUserInfo].ORG_ACCOUNT.MOBILE;
    paramer[@"CODE_SOURCE"] = @"upMobile";
    [NetWorkingManager postWithUrlString:[NetWorkingURL sendVeriCode] Parameter:paramer Success:^(id object) {
        if ([object[@"STATE"] isEqualToString:@"20000"]) {
        
        }
    } Fail:^(id object) {
        
    }];

}

/**  下一步的点击方法  */
- (void)clickButton{
    __weak typeof(self) weakSelf = self;
    if (self.getCode.codeTextField.text.length != 6) {
        [YJProgressHUD showMessage:@"请输入正确的验证码" inView:self.view];
        return;
    }
    NSMutableDictionary *paramer = [NSMutableDictionary dictionary];
    /**  这是保存在本地的手机号  */
    paramer[@"MOBILE"] = [ZJUserInfoModel sharedUserInfo].ORG_ACCOUNT.MOBILE;
    paramer[@"MOBILE_CODE"] = self.getCode.codeTextField.text; /**  这是输入的验证码  */
    paramer[@"CODE_SOURCE"] = @"upMobile";
    [NetWorkingManager postWithUrlString:[NetWorkingURL getUpdateUserchekMobile] Parameter:paramer Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            [weakSelf.navigationController pushViewController:[[MyInforChangeDetailViewController alloc] init] animated:YES];
            
        }else{
            [YJProgressHUD showMessage:@"验证码错误" inView:weakSelf.view];
        }
    } Fail:^(id object) {
        
    }];

   
    
}


- (LGetCodeView *)getCode{
    if (!_getCode) {
        _getCode = [[LGetCodeView alloc] initWithFrame:CGRectMake([UIScreen zj_screenWScale] * 30, navHeight + [UIScreen zj_screenHScale] * 50, [UIScreen zj_screenWith] - 60 * [UIScreen zj_screenWScale], 40 * [UIScreen zj_screenHScale])];
        _getCode.delegate = self;
        
    }
    return _getCode;
}


- (UIButton *)changePhoneButton{
    if (!_changePhoneButton) {
        _changePhoneButton = ({
            UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(self.getCode.x, CGRectGetMaxY(self.getCode.frame) + [UIScreen zj_screenHScale] * 60, self.getCode.width, 40 * [UIScreen zj_screenHScale])];
            [button setTitle:@"下一步" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            button.layer.cornerRadius = 5;
            button.layer.masksToBounds = YES;
            button.backgroundColor = [UIColor themeColor];
            [button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
            button;
            
        });
    }
    return _changePhoneButton;
}


@end
